package ualrcdg.shared.dto;

import java.util.HashMap;

/**
 * Simple implementation of the "mediaScript" object. See CDG XML Specifications: Game Descriptor Files.
 */
public class MediaScript extends FSM_TransitionMap< String, String, MediaScriptEntry >
{
	public static final String END_TRANISITION = "#END#";
	public static final String NULL_TRANISITION = "#NULL_TRANSITION#";
	public static final String NULL_UPDATE = "#NULL_UPDATE#";
	
	private final String id;
	private final String name;
	private final HashMap< String, String > stateToPageIdMap;
	
	/**
	 * Primary constructor
	 *
	 * @param id the id of the MediaScript object to be created
	 * @param name the name of the MediaScript object to be created
	 * @param initialState the initialState of the MediaScript object to be created 
	 * @param acceptingStates the acceptingStates of the MediaScript object to be created
	 * @param stateToPageIdMap the stateToPageIdMap of the MediaScript object to be created
	 * @param transitionMap the transitionMap of the MediaScript object to be created
	 */
	public MediaScript( String id, String name, String initialState, String[] acceptingStates, HashMap< String, String > stateToPageIdMap, HashMap< String, HashMap< String, MediaScriptEntry > > transitionMap )
	{
		super( initialState, acceptingStates, transitionMap );
		this.id = id;
		this.name = name;
		this.stateToPageIdMap = new HashMap< String, String >( stateToPageIdMap.size( ) ); 
		this.stateToPageIdMap.putAll( stateToPageIdMap );
		
		System.out.println( "Parsed: " + this.toString( ) );
	}

	/*
	 * @see ualrcdg.shared.dto.FSM_TransitionMap#toString()
	 */
	@Override
	public String toString( )
	{
		return "MediaScript [<" + super.toString( ) + "> id=" + id + ", name=" + name + ", stateToPageIdMap=" + stateToPageIdMap.toString( ) + "]";
	}

	/**
	 * @return the id of this MediaScript instance
	 */
	public String getId( )
	{
		return id;
	}
	
	/**
	 * @return the name of this MediaScript instance
	 */
	public String getName( )
	{
		return name;
	}
	
	/**
	 * @param state the state number upon which the PageId lookup should be performed
	 * @return the PageId of the given state within this MediaScript instance
	 */
	public String getPageId( String state )
	{
		return stateToPageIdMap.get( state );
	}
}